<?php
class news_view extends SClass {

    public function process() {
        $xx = ServiceUtils::GetFactory()->getNewsService()->getNewsAll();
	$count =0;	

        $page = $this->getArgument('id')*20;
        $user = $this->getUserSecure();
        if ($user) {
            if ($user->getLevel() >= 2) {
        	   $this->assign('autorized', 1);
            }
        }

        $a = array();

	$i=1;
        
        while ($x = $xx->getNext()) {
            if ($i < $page-20){
	 		$i++;
			$count++;
			continue;
		};
            if ($i > $page) {
			$count++;
			continue;
	
		    
		}    ;       
            $a[] = array(
                'id' => $x->getId(),
                'title' => $x->getTitle(),
                'preview' => $x->getPreview(),
                'postdate' => $x->getPostdate(),
                'url' => Engine_LinkMaker::GetURLByContentID(
                    'news_post_view', $x->getId()),
                'urledit' => Engine_LinkMaker::GetURLByContentID(
                    'news_post_edit', $x->getId()),
                'urldelete' => Engine_LinkMaker::GetURLByContentID(
                    'news_post_delete', $x->getId())
            );
		$i++;
        }
	$counts = array();
	$i=0;
	while ( $i <= $count/20){
		$counts[$i] = $i+1;
		$i++;
	}
	$this->assign('count', $counts);
	$this->assign('postArray', $a);


    }

}
